home *** CD-ROM | disk | FTP | other *** search
- /******************** ***********************/
- //
- // Player PRO 5.0 - DRIVER SOURCE CODE -
- //
- // Library Version 5.0
- //
- // To use with MAD Library for Mac: Symantec, CodeWarrior and MPW
- //
- // Antoine ROSSET
- // 16 Tranchees
- // 1206 GENEVA
- // SWITZERLAND
- //
- // COPYRIGHT ANTOINE ROSSET 1996, 1997, 1998
- //
- // Thank you for your interest in PlayerPRO !
- //
- // FAX: (+41 22) 346 11 97
- // PHONE: (+41 79) 203 74 62
- // Internet: RossetAntoine@bluewin.ch
- //
- /******************** ***********************/
-
- #include "669.h"
- #include "MAD.h"
- #include "RDriver.h"
-
- #if defined(powerc) || defined(__powerc)
- enum {
- PlayerPROPlug = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( OSType)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( Ptr)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( MADMusic*)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( PPInfoRec*)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof( MADDriverSettings*)))
- };
-
- ProcInfoType __procinfo = PlayerPROPlug;
- #else
- #include <A4Stuff.h>
- #endif
-
- short Tdecode16( void *msg_buf)
- {
- unsigned char *buf = msg_buf;
-
- return ( (short) buf[1] << 8) | ( (short) buf[0]);
- }
-
- Ptr MADPlugNewPtr( long size, MADDriverSettings* init)
- {
- if( init->sysMemory) return NewPtrSys( size);
- else return NewPtr( size);
- }
-
- Ptr MADPlugNewPtrClear( long size, MADDriverSettings* init)
- {
- if( init->sysMemory) return NewPtrSysClear( size);
- else return NewPtrClear( size);
- }
-
- Cmd* GetMADCommand( register short PosX, register short TrackIdX, register PatData* tempMusicPat)
- {
- if( PosX < 0) PosX = 0;
- else if( PosX >= tempMusicPat->header.size) PosX = tempMusicPat->header.size -1;
-
- return( & (tempMusicPat->Cmds[ (tempMusicPat->header.size * TrackIdX) + PosX]));
- }
-
- void pStrcpy(register unsigned char *s1, register unsigned char *s2)
- {
- register short len, i;
-
- len = *s2;
- for ( i = 0; i <= len; i++) s1[ i] = s2[ i];
- }
- void mystrcpy( Ptr a, Ptr b)
- {
- BlockMove( b + 1, a, b[ 0]);
- }
-
- OSErr Convert6692Mad( Ptr AlienFile, long MODSize, MADMusic *theMAD, MADDriverSettings *init)
- {
- SixSixNine *the669;
- short i, PatMax, x, z;
- long sndSize, OffSetToSample, OldTicks, temp;
- Ptr MaxPtr;
- OSErr theErr;
- Ptr theInstrument[ 64], destPtr;
- unsigned short tempS;
- short Note, Octave;
- Byte *thePasByte;
-
- /**** Variables pour le MAD ****/
- Cmd *aCmd;
-
- /**** Variables pour le MOD ****/
-
- struct PatSix *PatInt;
- struct PatCmd *theCommand;
- struct SampleInfo *SInfo;
- /********************************/
-
- the669 = (SixSixNine*) AlienFile;
-
- theMAD->header = (MADSpec*) MADPlugNewPtrClear( sizeof( MADSpec), init);
-
- MaxPtr = (Ptr)((long) the669 + MODSize);
-
- OffSetToSample = 0x1f1L + (long) the669->NOS * 25L + (long) the669->NOP * 0x600L;
-
- for( i = 0; i < the669->NOS ; i++)
- {
- temp = (long) the669;
- temp += 0x1f1L + i*25L + 13L;
-
- SInfo = (SampleInfo*) temp;
-
- SInfo->length = Tdecode16( &SInfo->length);
- SInfo->loopStart = Tdecode16( &SInfo->loopStart);
- SInfo->loopEnd = Tdecode16( &SInfo->loopEnd);
-
- theInstrument[i] = (Ptr) ((long) the669 + (long) OffSetToSample);
- OffSetToSample += SInfo->length;
- }
-
- /******** Le 669 a ÄtÄ lu et analysÄ ***********/
- /******** Copie des informations dans le MAD ***/
-
- theMAD->header->MAD = 'MADI';
- for(i=0; i<32; i++) theMAD->header->name[i] = the669->message[i];
-
- mystrcpy( theMAD->header->infos, (Ptr) "\pConverted by PlayerPRO 669 Plug (⌐Antoine ROSSET <rossetantoine@bluewin.ch>)");
-
- theMAD->header->numPointers = 128; //the669->loopOrder;
- theMAD->header->tempo = 125;
- theMAD->header->speed = 6;
- theMAD->header->numPat = the669->NOP;
- for(i=0; i<128; i++)
- {
- theMAD->header->oPointers[ i] = the669->orderList[ i];
- if( theMAD->header->oPointers[ i] >= theMAD->header->numPat) theMAD->header->oPointers[ i] = theMAD->header->numPat-1;
- }
- theMAD->header->numChn = 8;
-
- for( i = 0; i < MAXTRACK; i++)
- {
- if( i % 2 == 0) theMAD->header->chanPan[ i] = MAX_PANNING/4;
- else theMAD->header->chanPan[ i] = MAX_PANNING - MAX_PANNING/4;
-
- theMAD->header->chanVol[ i] = MAX_VOLUME;
- }
-
- theMAD->header->generalVol = 64;
- theMAD->header->generalSpeed = 80;
- theMAD->header->generalPitch = 80;
-
- theMAD->fid = ( InstrData*) MADPlugNewPtrClear( sizeof( InstrData) * (long) MAXINSTRU, init);
- if( !theMAD->fid) return MADNeedMemory;
-
- theMAD->sample = ( sData**) MADPlugNewPtrClear( sizeof( sData*) * (long) MAXINSTRU * (long) MAXSAMPLE, init);
- if( !theMAD->sample) return MADNeedMemory;
-
- for( i = 0; i < MAXINSTRU; i++) theMAD->fid[ i].firstSample = i * MAXSAMPLE;
-
- for(i=0; i<the669->NOS; i++)
- {
- temp = (long) the669;
- temp += 0x1f1L + i*25L + 13L;
-
- SInfo = (SampleInfo*) temp;
-
- if( SInfo->length > 0)
- {
- sData *curData;
-
- theMAD->fid[ i].numSamples = 1;
- theMAD->fid[i].volFade = DEFAULT_VOLFADE;
-
- curData = theMAD->sample[ i*MAXSAMPLE + 0] = (sData*) MADPlugNewPtrClear( sizeof( sData), init);
-
- curData->size = SInfo->length;
- curData->loopBeg = 0;
- curData->loopSize = 0;
- curData->vol = 64;
- curData->c2spd = NOFINETUNE;
- curData->loopType = 0;
- curData->amp = 8;
-
- curData->relNote = 0;
- // for( x = 0; x < 22; x++) curData->name[x] = instru[i]->name[x];
-
- curData->data = MADPlugNewPtr( curData->size, init);
- if( curData->data == 0L) DebugStr("\pInstruments: I NEED MEMORY !!! NOW !");
-
- BlockMove( theInstrument[i], curData->data, curData->size);
-
- destPtr = curData->data;
- for( temp = 0; temp < curData->size; temp++) *(destPtr + temp) -= 0x80;
- }
- else theMAD->fid[ i].numSamples = 0;
- }
-
- PatInt = ( struct PatSix*) the669 + 0x1f1 + the669->NOS * 0x19;
-
- temp = (long) the669;
- temp += 0x1f1L + (long) the669->NOS * 0x19L;
-
- PatInt = ( struct PatSix*) temp;
-
- /***** TEMPORAIRE ********/
-
- theMAD->header->numChn = 8;
- // theMAD->header->PatMax = 1;
-
- for( i = 0; i < theMAD->header->numPat; i++)
- {
- theMAD->partition[ i] = (PatData*) MADPlugNewPtrClear( sizeof( PatHeader) + theMAD->header->numChn * 64L * sizeof( Cmd), init);
- theMAD->partition[ i]->header.size = 64L;
- theMAD->partition[ i]->header.compMode = 'NONE';
- for( x = 0; x < 20; x++) theMAD->partition[ i]->header.name[ x] = 0;
- theMAD->partition[ i]->header.patBytes = 0L;
- theMAD->partition[ i]->header.unused2 = 0L;
-
- for( x = 0 ; x < 64; x++)
- {
- for( z = 0; z<theMAD->header->numChn; z++)
- {
- aCmd = GetMADCommand( x, z, theMAD->partition[ i]);
-
- theCommand = &PatInt[ i].Cmds[ x][ z];
- if( (Ptr) theCommand >= MaxPtr) Debugger();
-
- thePasByte = ( Byte*) theCommand;
-
- if( thePasByte[0] == 0xFF)
- {
- aCmd->cmd = 0;
- aCmd->arg = 0;
- aCmd->ins = 0;
- aCmd->note = 0xFF;
- aCmd->vol = 0xFF;
- }
- else if( thePasByte[0] == 0xFE)
- {
- aCmd->ins = 0;
- aCmd->note = 0xFF;
- aCmd->cmd = 0;
- aCmd->arg = 0;
-
- aCmd->vol = theCommand->Volume;
- aCmd->vol = (aCmd->vol * 64) / 15;
- }
- else
- {
- aCmd->ins = theCommand->Instru + 1;
- aCmd->note = theCommand->AmigaPeriod;
-
- Note = (aCmd->note & 0xF0) >> 4;
- Octave = (aCmd->note & 0x0F);
-
- aCmd->note = Note*12 + Octave;
-
- if( aCmd->note == 0) aCmd->note = 0xFF;
- else aCmd->note += 24;
-
- aCmd->vol = theCommand->Volume;
- aCmd->vol = (aCmd->vol * 64) / 15;
- }
-
- if( thePasByte[2] == 0xFF)
- {
- aCmd->cmd = 0;
- aCmd->arg = 0;
- }
- else
- {
- aCmd->cmd = 0;
- aCmd->arg = 0;
- }
- }
- }
- }
-
- return noErr;
- }
-
- OSErr Extract669Info( PPInfoRec *info, Ptr AlienFile)
- {
- SixSixNine *the669 = (SixSixNine*) AlienFile;
- long PatternSize;
- short i;
- short maxInstru;
- short tracksNo;
-
- /*** Signature ***/
-
- info->signature = '669 ';
-
- /*** Internal name ***/
-
- the669->message[ 30] = '\0';
- MADstrcpy( info->internalFileName, ( the669->message));
-
- /*** Total Patterns ***/
-
- info->totalPatterns = 0;
-
- /*** Partition Length ***/
-
- info->partitionLength = 0;
-
- /*** Total Instruments ***/
-
- info->totalInstruments = 0;
-
- MADstrcpy( info->formatDescription, "669 Plug");
-
- return noErr;
- }
-
- OSErr Test669File( Ptr AlienFile)
- {
- SixSixNine *the669 = (SixSixNine*) AlienFile;
-
- if( the669->marker == 0x6669 || the669->marker == 0x6966) return noErr;
- else return MADFileNotSupportedByThisPlug;
- }
-
- OSErr main( OSType order, char *AlienFileName, MADMusic *MadFile, PPInfoRec *info, MADDriverSettings *init)
- {
- OSErr myErr;
- Ptr AlienFile;
- short vRefNum, iFileRefI;
- long dirID, sndSize;
-
- #ifndef powerc
- long oldA4 = SetCurrentA4(); //this call is necessary for strings in 68k code resources
- #endif
-
- c2pstr( AlienFileName);
-
- myErr = noErr;
-
- switch( order)
- {
- case 'IMPL':
- myErr = FSOpen( (unsigned char*) AlienFileName, 0, &iFileRefI);
- if( myErr == noErr)
- {
- GetEOF( iFileRefI, &sndSize);
-
- // ** MEMORY Test Start
- AlienFile = MADPlugNewPtr( sndSize * 2L, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- // ** MEMORY Test End
-
- else
- {
- DisposePtr( AlienFile);
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
- if( myErr == noErr)
- {
- myErr = Test669File( AlienFile);
- if( myErr == noErr)
- {
- myErr = Convert6692Mad( AlienFile, GetPtrSize( AlienFile), MadFile, init);
- }
- }
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- case 'TEST':
- myErr = FSOpen( (unsigned char*) AlienFileName, 0, &iFileRefI);
- if( myErr == noErr)
- {
- sndSize = 1024L;
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- else
- {
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
-
- myErr = Test669File( AlienFile);
-
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- case 'INFO':
- myErr = FSOpen( (unsigned char*) AlienFileName, 0, &iFileRefI);
- if( myErr == noErr)
- {
- GetEOF( iFileRefI, &info->fileSize);
-
- sndSize = 5000L; // Read only 5000 first bytes for optimisation
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- else
- {
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
- if( myErr == noErr)
- {
- myErr = Extract669Info( info, AlienFile);
- }
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- default:
- myErr = MADOrderNotImplemented;
- break;
- }
-
- p2cstr( (unsigned char*) AlienFileName);
-
- #ifndef powerc
- SetA4( oldA4);
- #endif
- return myErr;
- }